package TipTok;

import java.util.*;

/**
 * 字节跳动题目
 */
public class Test {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String s = scanner.nextLine();
        List<Integer> list = new ArrayList<>();

        s = s.substring(1, s.length() - 1);

        String[] split = s.split(",");

        for (String str : split) {
            int i = Integer.parseInt(str);
            list.add(i);
        }

        int[] arr = new int[list.size()];

        for (int i = 0; i < list.size(); i++) {
            arr[i] = list.get(i);
        }
        boolean res = Third(arr);
        System.out.println(res);
    }

    public static int dp_arr(int[] arr) {
        int[] op = new int[arr.length];
        op[0] = arr[0];
        op[1] = Math.max(arr[0], arr[1]);
        for (int i = 2; i < arr.length; i++) {
            int a = op[i - 2] + arr[i];
            int b = op[i - 1];
            op[i] = Math.max(a, b);
        }
        return op[arr.length - 1];
    }

    //十六进制转十进制
    public static int covert(String content) {
        int number = 0;
        String[] HighLetter = {"A", "B", "C", "D", "E", "F"};
        Map<String, Integer> map = new HashMap<>();

        for (int i = 0; i <= 9; i++) {
            map.put(i + "", i);
        }

        for (int i = 10; i < HighLetter.length + 10; i++) {
            map.put(HighLetter[i - 10], i);
        }

        String[] str = new String[content.length()];

        for (int i = 0; i < str.length; i++) {
            str[i] = content.substring(i, i + 1);
        }
        for (int i = 0; i < str.length; i++) {
            number += map.get(str[i]) * Math.pow(16, str.length - 1 - i);
        }
        return number;
    }


    public static boolean Third(int[] bills) {
        int five = 0, ten = 0;
        for (int bill : bills) {
            if (bill == 5) {
                five++;
            } else if (bill == 10) {
                if (five == 0) {
                    return false;
                }
                five--;
                ten++;
            } else {
                if (five > 0 && ten > 0) {
                    five--;
                    ten--;
                } else if (five >= 3) {
                    five -= 3;
                } else {
                    return false;
                }
            }
        }
        return true;
    }
}

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int c = scanner.nextInt();
        Map<Integer, List<Integer>> map = new HashMap<>();
        for (int i = 0; i < c; i++) {
            map.put(i + 1, new ArrayList<Integer>());
        }
        for (int i = 0; i < n; i++) {
            int length = scanner.nextInt();
            if (length != 0) {
                for (int j = 0; j < length; j++) {
                    List<Integer> list = map.get(scanner.nextInt());
                    list.add(i);
                }
            }
        }
        int count = 0;
        for (List<Integer> list : map.values()) {
            if (list.size() > 1) {
                boolean flag = false;
                int size = list.size();
                for (int i = 0; i < size - 1; i++) {
                    if (list.get(i + 1) - list.get(i) < m) {
                        count++;
                        flag = true;
                        break;
                    }
                }
                if (!flag) {
                    if (list.get(0) + n - list.get(size - 1) < m) {
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}

class Main2 {
    public static void main(String[] args) {
        int[] arr = new int[]{150, 172, 163, 180, 178, 160, 172, 154, 165, 158};
        Arrays.sort(arr);
        for (int i : arr) {
            System.out.print(i + " ");
        }
        char ch1 = 97;
        char ch2 = 'a';
        System.out.println(" ch1=" + ch1);
        System.out.println(" ch2=" + ch2);
        boolean bOK = checkValue(6144);
        boolean bOK2 = checkValue(5073);
        boolean bOK3 = checkValue(4831);
        boolean bOK4 = checkValue(8300);
        System.out.println(bOK);
        System.out.println(bOK2);
        System.out.println(bOK2);
        System.out.println(bOK3);
    }

    void checkJj() {
        checkValue(11);
        hhh();
        checkValue(11);
    }

    void hhh() {

    }

    static boolean checkValue(int num) {
        int d1, d2, d3;
        int checkNum, nRemain, rem;

        checkNum = num % 10;
        nRemain = num / 10;
        d3 = nRemain % 10;
        nRemain /= 10;
        d2 = nRemain % 10;
        nRemain /= 10;
        d1 = nRemain % 10;
        rem = (d1 + d2 + d3) % 7;
        return rem == checkNum;
    }
}

